home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / text / hyper / ADtoHT2_1.lha / Source.lha / MyLib.lha / string / strncat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-05  |  561 b   |  48 lines

  1. #include <string.h>
  2.  
  3. /************************************************************************/
  4.  
  5. #if defined(__GNUC__) && defined(mc68000)
  6.  
  7. asm("
  8.     .globl    _strncat
  9. _strncat:
  10.     moveml    sp@(4:W),d0/a0
  11.     movel    d0,a1
  12.     movel    sp@(12),d1
  13.     jeq    L1
  14. L3:    tstb    a1@+
  15.     jne    L3
  16.     subqw    #1,a1
  17. L2:    moveb    a0@+,a1@+
  18.     jeq    L1
  19.     subql    #1,d1
  20.     jne    L2
  21.     clrb    a0@
  22. L1:    rts
  23. ");
  24.  
  25. #else
  26.  
  27. char *strncat(char *s1, const char *s2, size_t n)
  28.  
  29. {
  30.   if (n != 0)
  31.     {
  32.       char *s=s1;
  33.  
  34.       while(*s++)
  35.     ;
  36.  
  37.       --s;
  38.  
  39.       while((*s++=*s2++) && (--n != 0))
  40.     ;
  41.  
  42.       *s=0;
  43.     }
  44.   return s1;
  45.  
  46. #endif
  47.